<%@ page language="java" contentType="text/html; charset=windows-1256" pageEncoding="windows-1256"%>
<%@ page import="java.util.*" %>
<%@ page import="java.io.IOException" %>
<%@ page import="java.sql.ResultSet" %>
<%@ page import="java.sql.Statement" %>
<%@ page import="common.Configuration" %>    
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Edit Questionnaire</title>
<script language ="javascript">
function backhome () {
	window.location.href="Accueil.jsp";
}
</script>
</head>
<body>
<form method='post' action='SaveQuest' name='form1'>
<table width="100%">
<tr><td align ="center" colspan="2"><b><u>Are You sure you want to Edit The Following Questionnaire</u></b> </td></tr>
<tr><td colspan="2">&nbsp;</td></tr>
<tr><td width="50%">
<%
String questid    = request.getParameter("qstid");
Statement stmt    = null;
Statement stmt2   = null;
ResultSet rst     = null;
ResultSet rst2    = null;
ResultSet rst3    = null;
ResultSet subrst  = null;
ResultSet subrst2 = null;
stmt  = Configuration.GetStatement();
stmt2 = Configuration.GetStatement();
int qlcount  = 0;
int qmcount  = 0;
int qucount  = 0;
String titre = "";
 try  { 
	      out.print("<b><u>Questions Libres:</u></b><br>");
		  rst = stmt.executeQuery("select * from question where idquestiongroup = " + questid + " and idquestiontype = 1");
          while( rst.next() )     
           {    
        	  titre = rst.getString("QuestionTitle");
        	  qlcount = qlcount + 1;
        	  String libre="libre";
        	  String qstdesc = rst.getString("QuestionDesc"); 
        	  libre+=qlcount;
        	  out.print("Libelle <input type='text' name='");out.print(libre+"' value = '");out.print(qstdesc + "'");
        	  out.print(" size='40'  />"); out.print("<br><br>");
            } 
         rst.close();  
         out.print("<b><u>Questions Multiples:</u></b><br>");
         rst2 = stmt.executeQuery("select * from question where idquestiongroup = " + questid + " and idquestiontype = 2");
         while( rst2.next() )     
          {    
        	String qstdesc = rst2.getString("QuestionDesc");
        	int idquestion = rst2.getInt("idquestion");
        	int subcount = 0;
	       	String mult="QM";
	       	String nbrPosM="nbrPosM";
	       	mult+=qmcount;
	       	nbrPosM+=qmcount;
	       	out.print("Libelle <input type='text' name='");out.print(mult+"' value = '");out.print(qstdesc + "'");
	        out.print(" size='40'  />");out.print("<br>");
	        subrst = stmt2.executeQuery("select * from subquestion where idquestion = " + idquestion);
	        while( subrst.next() )     
	          {    
	        	String subqstdesc = subrst.getString("SubQuestionDesc");
	        	out.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"); 
	        	out.print("<input type='text' value='" + subqstdesc +"' name='QM");out.print(qmcount + "res" + subcount + "'/><br>");
				subcount = subcount +1;
	          }
	        out.print("<input type='hidden' value='");out.print(subcount +"' name='");out.print("pos" + qmcount + "'/>");
	        qmcount = qmcount + 1;
	        subrst.close();
           } 
        rst2.close();
        out.print("<br><b><u>Questions Uniques:</u></b><br>");
        rst3 = stmt.executeQuery("select * from question where idquestiongroup = " + questid + " and idquestiontype = 3");
        while( rst3.next() )     
         { 
        	String qstdesc = rst3.getString("QuestionDesc");
        	int idquestion = rst3.getInt("idquestion");
        	int subcount = 0;
	       	String unq="QU";
	       	String nbrPosU="nbrPosU";
	       	unq+=qucount;
	       	nbrPosU+=qucount;
	       	out.print("Libelle <input type='text' name='");out.print(unq+"' value = '");out.print(qstdesc + "'");
	        out.print(" size='40'  />");out.print("<br>");
	        subrst2 = stmt2.executeQuery("select * from subquestion where idquestion = " + idquestion);
	        while( subrst2.next() )     
	          {    
	        	String subqstdesc = subrst2.getString("SubQuestionDesc");
	        	out.print("&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;"); 
	        	out.print("<input type='text' value='" + subqstdesc +"' name='QU");out.print(qucount + "res" + subcount + "'/><br>");
				subcount = subcount +1;
	          }	
	        subrst2.close();
	        out.print("<input type='hidden' value='");out.print(subcount +"' name='");out.print("posU" + qucount + "'/>");
	        qucount = qucount + 1;
        } 
     rst3.close();     
	}
	     catch( Exception e )           { 
		 System.out.println( "Exception Error:  " + e );       
 }
	out.print("<input type='hidden' name='titre'   value='"); out.print(titre +"'/>");
   	out.print("<input type='hidden' name='nbrQL'   value='" + qlcount + "'/>");
   	out.print("<input type='hidden' name='nbrQM'   value='" + qmcount + "'/>");
   	out.print("<input type='hidden' name='nbrQU'   value='" + qucount + "'/>");
   	out.print("<input type='hidden' name='questid' value='" + questid + "'/>");
%>
</td>
 <td width="50%" align="right" valign="top">
<input type="submit" value="Edit & Save" > 
<input type="button" value =" <<-- Home " onclick="backhome()">
</td>
</tr>
</table>
</form>
</body>
</html>